import 'package:flutter/material.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(

      home: HomePage(),
    );
  }
}


class HomePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return HomePageState();
  }
}


class HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {

  int _selectIndex = 0;


  TabController _tabController;

  List<String> tabText = ['数学', '历史', '语文'];


  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: tabText.length, vsync: this);
  }

  void _onItemTap(int index) {
    setState(() {
      _selectIndex = index;
    });
  }


  @override
  Widget build(BuildContext context) {

    return Scaffold(


      ///导航栏
      appBar: AppBar(

        title: Text('HomePage'),

        //右侧菜单
        actions: <Widget>[

          IconButton(icon: Icon(Icons.share), onPressed: () {})
        ],

        ///TabBar
        bottom: TabBar(

          controller: _tabController,

          tabs: tabText.map((e) {
            return Tab(text: e,);
          }).toList(),
        ),


      ),


      body: TabBarView(

          controller: _tabController,

          children: tabText.map((e) {
            return Container(

              alignment: Alignment.center,

              child: Text(e, textScaleFactor: 5,),

            );
          }).toList()

      ),

      ///抽屉
      drawer: MyDrawer(),


      ///NavigationBar
//      bottomNavigationBar: BottomNavigationBar(
//
//        items: [
//
//          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('home')),
//          BottomNavigationBarItem(
//              icon: Icon(Icons.business), title: Text('business')),
//          BottomNavigationBarItem(
//              icon: Icon(Icons.school), title: Text('school')),
//          BottomNavigationBarItem(
//              icon: Icon(Icons.people), title: Text('people')),
//
//        ],
//
//        //不设置这条，选中的item会变大并且没有文字 少于四个没有变化
//        type: BottomNavigationBarType.fixed,
//
//        //不添加颜色会显示为白色 少于四个没有变化
//        selectedItemColor: Colors.blue,
//
//        unselectedItemColor: Colors.grey,
//
//        currentIndex: _selectIndex,
//
//        onTap: _onItemTap,
//
//      ),

      ///打洞效果的底部导航栏
      //一个floatingActionButton + scaffold的属性floatingActionButtonLocation + BottomAppBar
      floatingActionButton: FloatingActionButton(

        onPressed: () {},

        child: Icon(Icons.add),

      ),

      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

      bottomNavigationBar: BottomAppBar(

        shape: CircularNotchedRectangle(),

        child: Row(

          mainAxisAlignment: MainAxisAlignment.spaceAround,

          children: <Widget>[

            IconButton(icon: Icon(Icons.home), onPressed: () {},),
            SizedBox(), //中间位置空出
            IconButton(icon: Icon(Icons.business), onPressed: () {}),
          ],
        ),
      ),

    );
  }


}



///抽屉
class MyDrawer extends StatelessWidget {

  MyDrawer({Key key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Drawer(

      //移除抽屉菜单顶部默认留白
      child: MediaQuery.removePadding(

          context: context,
          child: Column(

            crossAxisAlignment: CrossAxisAlignment.start,

            children: <Widget>[


              Padding(

                padding: EdgeInsets.only(top: 38),

                child: Row(

                  children: <Widget>[

                    Padding(

                      padding: EdgeInsets.symmetric(horizontal: 16),

                      child: ClipOval(

                        child: Image.asset('images/36.jpg', width: 80,),

                      ),
                    )
                  ],

                ),
              ),


              Text('Sky', style: TextStyle(fontWeight: FontWeight.bold),),

              Expanded(
                child: ListView(
                  children: <Widget>[
                    ListTile(
                      leading: const Icon(Icons.add),
                      title: const Text('Add account'),
                    ),
                    ListTile(
                      leading: const Icon(Icons.settings),
                      title: const Text('Manage accounts'),
                    ),
                  ],
                ),
              ),

            ],

          )

      ),
    );
  }
}